package com.ruoyi.web.controller.Money;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Money.domain.Money;
import com.ruoyi.Money.service.IMoneyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 金额流向 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-09
 */
@Controller
@RequestMapping("/Money/money")
public class MoneyController extends BaseController
{
    private String prefix = "Money/money";
	
	@Autowired
	private IMoneyService moneyService;
	
	@RequiresPermissions("Money:money:view")
	@GetMapping()
	public String money()
	{
	    return prefix + "/money";
	}
	
	/**
	 * 查询金额流向列表
	 */
	@RequiresPermissions("Money:money:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Money money)
	{
		startPage();
        List<Money> list = moneyService.selectMoneyList(money);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出金额流向列表
	 */
	@RequiresPermissions("Money:money:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Money money)
    {
    	List<Money> list = moneyService.selectMoneyList(money);
        ExcelUtil<Money> util = new ExcelUtil<Money>(Money.class);
        return util.exportExcel(list, "money");
    }
	
	/**
	 * 新增金额流向
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存金额流向
	 */
	@RequiresPermissions("Money:money:add")
	@Log(title = "金额流向", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Money money)
	{		
		return toAjax(moneyService.insertMoney(money));
	}

	/**
	 * 修改金额流向
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Money money = moneyService.selectMoneyById(id);
		mmap.put("money", money);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存金额流向
	 */
	@RequiresPermissions("Money:money:edit")
	@Log(title = "金额流向", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Money money)
	{		
		return toAjax(moneyService.updateMoney(money));
	}
	
	/**
	 * 删除金额流向
	 */
	@RequiresPermissions("Money:money:remove")
	@Log(title = "金额流向", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(moneyService.deleteMoneyByIds(ids));
	}
	
}
